package com.javaweb.cwj.controller;


import com.javaweb.cwj.R;
import com.javaweb.cwj.entity.EduCourse;
import com.javaweb.cwj.entity.vo.CourseInfoVo;
import com.javaweb.cwj.exception.cwjException;
import com.javaweb.cwj.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-05-13
 */
@RestController
@RequestMapping("/eduService/cwj/course")
@CrossOrigin
public class EduCourseController {
    @Autowired
    private EduCourseService courseService;
    @PostMapping("addCourse")
     public R addCourse(@RequestBody CourseInfoVo courseInfoVo){
        String id = courseService.addCourse(courseInfoVo);
         return R.ok().data("CourseId",id);
     }

    @GetMapping("findcourseInfoById/{courseId}")
    public R updateCourseInfoById(@PathVariable String courseId){
        CourseInfoVo courseInfoVo = courseService.selectCourseInfo(courseId);
        return R.ok().data("courseInfo",courseInfoVo);
    }
    @PostMapping("update")
    public R updateCourseInfo(
                              @RequestBody CourseInfoVo courseInfoVo){
       int i =  courseService.updateCourse(courseInfoVo);
       if(i==0){
          throw new cwjException(20001,"修改失败");
       }
       return  R.ok();
    }
}

